#include "headfile.h"
#include "time.h"

hw_timer_t *timer = NULL;
hw_timer_t *timer2 = NULL;

extern uint8_t analyze_flag;
extern uint8_t master_status;

void IRAM_ATTR timer_event()
{   
    master_status = SEND;
    analyze_flag = RUN;
    analysis();
}

void IRAM_ATTR timer_event3()
{
    master_status = SEND;
    analyze_flag = ERROR;
    analysis();
}

void timer_init()
{
    //定时器编号0-3
    //分频系数(基频80M，80分频为1us)
    //true向上计数。false向下计数
    timer = timerBegin(0,80,true);

    //已初始化的定时器
    //中断服务函数
    //边沿触发true电平触发false
    timerAttachInterrupt(timer,timer_event,true);

    //已初始化的定时器
    //计数值
    //true重装载false不重装载
    timerAlarmWrite(timer,243,false);

    timer2 = timerBegin(3,80,true);
    timerAttachInterrupt(timer2,timer_event3,true);
    timerAlarmWrite(timer2,1600000,false);  // 1.6s
}